using Microsoft.AspNetCore.Mvc;
using Web.Application.Common.Interface.IServer;
using Web.Application.ReqDto;
using Web.Application.ReqDto.ServerDto;
using Web.Application.ResDto;
using Web.Application.Utils;
using Web.Services.Services;

namespace Web.Api.Controllers
{
    [ApiController]
    [Route("[controller]")]
    // 请求地址 http://localhost:5003/user
    public class UserController : ControllerBase
    {

        private readonly IUserServices _users;
        public UserController(IUserServices users)
        {
            _users = users;
        }

        // get
        public string getUser([FromQuery] PageFromQuery query)
        {
            var tmp = _users.GetListOrByUserName(query);

            return tmp;
        }

        // post
        [HttpPost]
        public async Task<string> addUser(UserDTO userDto)
        {
            var tmp = await _users.AddUser(userDto);

            return tmp;
        }

        // put
        [HttpPut("{id}")]
        public async Task<string> updateUser(UserDTO userDto, Guid id)
        {
            var tmp = await _users.UpdateUser(id, userDto);

            return tmp;
        }

        // delete
        [HttpDelete("{id}")]
        public async Task<string> deleteUser(Guid id)
        {
            var tmp = await _users.DeleteUser(id);

            return tmp;
        }

        //根据账号密码获取openid
        [HttpGet("{id}")]
        public string GetOpenId(string id)
        {
            var tmp = _users.GetOpenId(id);

            return tmp;
        }
        //根据账号密码获取openid
        [HttpPost("AddOpenId")]
        public async Task<string> AddOpenId(UserOpenIdDTO openIdDTO)
        {
            var tmp = await _users.AddOpenid(openIdDTO);

            return tmp;
        }
        [HttpPost("GetByStudentInfo")]
        public string GetByStudentInfo(UserForAuth user)
        {
            var tmp = _users.GetByStudentInfo(user);

            return tmp;
        }
    }
}